﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PhatPhucLoc.dao;
using PhatPhucLoc.model;

namespace PhatPhucLoc.view
{
    public partial class FormNhomHang : Form
    {
        public FormNhomHang()
        {
            InitializeComponent();
            formNhomHangLoad();
        }

        public void formNhomHangLoad()
        {
            DataTable dt = NhomHangDAO.GetAll();
            dgvNhomHang.DataSource =  dt;
        }

        private void formNhomHang_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.formNhomHang_KeyDown);
        }

        private void formNhomHang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            else if (e.KeyCode == Keys.F4)
            {
                tsbThoat.PerformClick();
            }
        }

        private void dgvNhomHang_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            FormNhomHang formNhomHang = this;
            NhomHangModel NhomHangModel = new NhomHangModel();
            NhomHangModel.Id = dgvNhomHang.CurrentRow.Cells["Id"].Value.ToString();
            NhomHangModel.Ten = dgvNhomHang.CurrentRow.Cells["tenNH"].Value.ToString();
            NhomHangModel.GhiChu = dgvNhomHang.CurrentRow.Cells["GhiChu"].Value.ToString();
            NhomHangModel.NgayCapNhatCuoi = dgvNhomHang.CurrentRow.Cells["NgayCapNhatCuoi"].Value.ToString();

            FormThemNhomHang formThemNhomHang = new FormThemNhomHang(NhomHangModel, ref formNhomHang);
            formThemNhomHang.ShowDialog();
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            FormNhomHang formNhomHang = this;
            FormThemNhomHang formThemNhomHang = new FormThemNhomHang(ref formNhomHang);
            formThemNhomHang.ShowDialog();
        }

    }
}
